package com.example.shangjinlieren.provider;

import com.example.shangjinlieren.ResourceTable;
import com.example.shangjinlieren.compontents.ImageNetWork;
import com.example.shangjinlieren.entity.moneyList.OfferAReward;
import com.example.shangjinlieren.theme.MyColors;
import com.example.shangjinlieren.utils.RpxUtil;
import ohos.aafwk.ability.AbilitySlice;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.*;
import ohos.agp.components.element.ShapeElement;
import ohos.agp.utils.Color;
import ohos.agp.utils.LayoutAlignment;
import ohos.agp.utils.TextAlignment;

import java.util.ArrayList;
import java.util.List;

public class MoneyListProvider {
    private List<OfferAReward> list;
    private AbilitySlice abilitySlice;

    public MoneyListProvider(List<OfferAReward> list, AbilitySlice abilitySlice ) {
        this.list = list;
        this.abilitySlice = abilitySlice;
    }

    public List<DirectionalLayout> getComponent() {
        List<DirectionalLayout> directionalLayouts = new ArrayList<>();

        for (int i = 0; i <list.size() ; i++) {
            //顶部盒子
            DirectionalLayout OfferARewarditem = new DirectionalLayout(abilitySlice.getContext());
            OfferARewarditem.setWidth((int) RpxUtil.rpx(336,abilitySlice.getContext()));
            OfferARewarditem.setHeight((int) RpxUtil.rpx(340,abilitySlice.getContext()));
            OfferARewarditem.setMarginLeft((int) RpxUtil.rpx(26,abilitySlice.getContext()));
            OfferARewarditem.setMarginTop((int) RpxUtil.rpx(26,abilitySlice.getContext()));
            //获取数据
            OfferAReward offerAReward = list.get(i);
            DynamicOfferAReward dynamicOfferAReward = new DynamicOfferAReward(abilitySlice);
            //顶部布局
            StackLayout stackLayout = new StackLayout(abilitySlice.getContext());
            DependentLayout topText = new DependentLayout(abilitySlice.getContext());

            new ImageNetWork(abilitySlice,dynamicOfferAReward.img,offerAReward.getImg()).start();//获取图片
            //图片宽高
            dynamicOfferAReward.img.setWidth((int) RpxUtil.rpx(336,abilitySlice.getContext()));
            dynamicOfferAReward.img.setHeight((int) RpxUtil.rpx(210,abilitySlice.getContext()));
            dynamicOfferAReward.img.setScaleMode(Image.ScaleMode.STRETCH);
//            topText.setOrientation(DirectionalLayout.HORIZONTAL);//设置水平
            topText.setWidth((int) RpxUtil.rpx(336,abilitySlice.getContext()));
            topText.setHeight(MagicLayout.LayoutConfig.MATCH_CONTENT);
            StackLayout.LayoutConfig toptextlayoutConfig = new StackLayout.LayoutConfig(
                    (int) RpxUtil.rpx(336,abilitySlice.getContext()),
                    StackLayout.LayoutConfig.MATCH_CONTENT,LayoutAlignment.BOTTOM
            );
            topText.setLayoutConfig(toptextlayoutConfig);
//
            //播放量
            DependentLayout.LayoutConfig numslayoutConfig = new DependentLayout.LayoutConfig();
            numslayoutConfig.addRule(DependentLayout.LayoutConfig.ALIGN_PARENT_LEFT);
            dynamicOfferAReward.nums.setLayoutConfig(numslayoutConfig);
            dynamicOfferAReward.nums.setText(""+offerAReward.getNums());
            dynamicOfferAReward.nums.setTextSize((int) RpxUtil.rpx(30,abilitySlice.getContext()));
            dynamicOfferAReward.nums.setMarginLeft((int) RpxUtil.rpx(10,abilitySlice.getContext()));
            dynamicOfferAReward.nums.setMarginBottom((int) RpxUtil.rpx(5,abilitySlice.getContext()));
//            Color.rgb(255,255,255)
            Color color = new Color(Color.rgb(255,255,255));
            dynamicOfferAReward.nums.setTextColor(color);
            //评论量
            DependentLayout.LayoutConfig messageNumlayoutConfig = new DependentLayout.LayoutConfig();
            messageNumlayoutConfig.addRule(DependentLayout.LayoutConfig.ALIGN_PARENT_RIGHT);
            dynamicOfferAReward.messageNum.setText(""+offerAReward.getMessageNum());
            dynamicOfferAReward.messageNum.setTextColor(color);
            dynamicOfferAReward.messageNum.setTextSize((int) RpxUtil.rpx(30,abilitySlice.getContext()));
            dynamicOfferAReward.messageNum.setLayoutConfig(messageNumlayoutConfig);
            dynamicOfferAReward.messageNum.setMarginRight((int) RpxUtil.rpx(10,abilitySlice.getContext()));
            dynamicOfferAReward.messageNum.setMarginBottom((int) RpxUtil.rpx(5,abilitySlice.getContext()));
            topText.addComponent(dynamicOfferAReward.nums);
            topText.addComponent(dynamicOfferAReward.messageNum);
            ShapeElement shapeElement = new ShapeElement();
            shapeElement.setRgbColor(new RgbColor(255,255,255));
            OfferARewarditem.setBackground(shapeElement);
            stackLayout.addComponent(dynamicOfferAReward.img);
            stackLayout.addComponent(topText);
            //底部布局
            DirectionalLayout bottom = new DirectionalLayout(abilitySlice.getContext());
            bottom.setMarginLeft((int) RpxUtil.rpx(25,abilitySlice.getContext()));
            //标题
            dynamicOfferAReward.title.setText(offerAReward.getTitle());

            dynamicOfferAReward.title.setMarginTop((int) RpxUtil.rpx(25,abilitySlice.getContext()));
            dynamicOfferAReward.title.setTextSize((int) RpxUtil.rpx(30,abilitySlice.getContext()));
            //星际
            dynamicOfferAReward.star.setText(offerAReward.getStar());
            dynamicOfferAReward.star.setMarginTop((int) RpxUtil.rpx(15,abilitySlice.getContext()));
            dynamicOfferAReward.star.setTextSize((int) RpxUtil.rpx(25,abilitySlice.getContext()));
            dynamicOfferAReward.star.setTextColor(new Color(MyColors.secondColor));
            bottom.addComponent(dynamicOfferAReward.title);
            bottom.addComponent(dynamicOfferAReward.star);
            OfferARewarditem.addComponent(stackLayout);
            OfferARewarditem.addComponent(bottom);
            directionalLayouts.add(OfferARewarditem);
        }
        return directionalLayouts;
    }
    public  class DynamicOfferAReward{
        Image img  ;
        Text nums;
        Text messageNum;
        Text title;
        Text star;
        public DynamicOfferAReward(AbilitySlice abilitySlice) {
             img = new Image(abilitySlice.getContext());
             nums= new Text(abilitySlice.getContext());
             messageNum= new Text(abilitySlice.getContext());
             title= new Text(abilitySlice.getContext());
             star= new Text(abilitySlice.getContext());
        }
    }

}
